package com.ppq.ta.reinforcelearning;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.Scroller;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.LinearLayoutCompat;

import org.jetbrains.annotations.NotNull;

public class LinearLayoutSubClass extends LinearLayoutCompat {

    private final Scroller mScroller;

    private boolean flag = true;

    private int offsetY;

    private int duration;


    public LinearLayoutSubClass(@NonNull @NotNull Context context) {
        this(context, null);
    }

    public LinearLayoutSubClass(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LinearLayoutSubClass(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mScroller = new Scroller(context);
        duration = 10000;

    }


    public void beginScroll() {
        if (flag) {
            offsetY = -100;
            int startX = -300;
            int startY = -90;
            int dx = -500;
            int dy = 0;
            mScroller.startScroll(startX, startY, dx, dy, duration);
            flag = false;
        } else {
            offsetY = 0;
            int startX = mScroller.getCurrX();
            int startY = mScroller.getCurrY();
            int dx = -startX;
            int dy = 0;
            mScroller.startScroll(startX, startY, dx, dy, duration);
            flag = true;
        }
        invalidate();
    }
}
